<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>表单提交</title>
    <script>
        function register(){
            //静态注册。
            var userName = document.getElementById("username");
            var pwd = document.getElementById("pwd");
            if(""==pwd.value ||""==userName.value){
                alert("账户或密码不能为null");
                return false;
            }
            return true;
        }

        // 动态注册。
        window.onload = function (){
            // 动态 注册。
            var form1 = document.getElementById("form1");

            form1.onsubmit=function (){
                if(""==form1.username1.value ||""==form1.pwd1.value){
                    alert("账户或密码不能为null");
                    return false;
                }
                return true;
            }

        }


    </script>
</head>
<body>

</body>
<form action="ok.html" id="form" onsubmit="return register()">
    p:<input type="text" id="username"><br>
    u:<input type="text" id="pwd"><br>
    <input type="submit" value="用户提交">
</form>

动态注册：
<form action="ok.html" id="form1">
    p:<input type="text" name="username1"><br>
    u:<input type="text" name="pwd1"><br>
    <input type="submit" value="用户提交">
</form>
</html>